/*
 * Copyright (c) 2007 T.Cogghe, D.Leroux, S.Lévignac, S.Rives
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
#include "fenetreTraitement.hh"
#include "fenetreFinale.hh"
#include "fenetreDark.hh"




IHM::FenetreTraitement::FenetreTraitement(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade)
	: Gtk::Window(cobject), //m_refGlade(refGlade),
	  barreProg(0), filTraitement(0), etatScroll(0), etat(0)
{
	Gtk::Button*b;

	getW(refGlade,barreProg,"progressionTraitement");
	getW(refGlade,etat,"etatTraitement");
	getW(refGlade,etatScroll,"scroll_fTra_etat");
	etatScroll->get_vscrollbar()->get_adjustment()->signal_changed().connect(mem_fun(*this,&FenetreTraitement::scroll));

	proxy_majProg.connect(sigc::mem_fun(*this,&FenetreTraitement::majProg));
	getW(refGlade,b,"b_Tra_Annuler");
	b->signal_clicked().connect(sigc::mem_fun(*this,&FenetreTraitement::annuler));
	proxy_fini.connect(sigc::mem_fun(*this,&FenetreTraitement::fini));
}

IHM::FenetreTraitement::~FenetreTraitement() {}


void IHM::FenetreTraitement::scroll() {
	etatScroll->get_vscrollbar()->set_value(
		etatScroll->get_vscrollbar()->get_adjustment()->get_upper()
	);
}


void IHM::FenetreTraitement::annuler() {
	IHM::env->traitementAnnule();
	IHM::env->fTra->hide();
	IHM::env->fDark->show();
}

void IHM::FenetreTraitement::majProg() {
	if(IHM::env->prog==0) {
		etat->get_buffer()->set_text(Glib::ustring(""));
	}
	etat->get_buffer()->insert_at_cursor(Glib::ustring(IHM::env->texte));
	etat->queue_draw();
	IHM::env->texte.clear();
	barreProg->set_fraction(IHM::env->prog);
}

void IHM::FenetreTraitement::fini() {
//	IHM::env->iFin->majCoef(1.);
	IHM::env->fTra->hide();
	IHM::env->fFin->cursCoef->set_value(IHM::env->iFin->calcCoefOptimal());
	IHM::env->fFin->show();
	
}


